package com.yesorno.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yesorno.constants.Constants;
import com.yesorno.ui.CustomTitleActivity;

public class TopicCommentActivity extends CustomTitleActivity {
	private Button goBack;
	private Button publish;
	RegBtnsClickListeners rbc = new RegBtnsClickListeners();

	private EditText topic_comment_comment;

	private long currentTopicId;
	private int type;

	/**
	 * 注册页面按钮的监听类
	 * 
	 * @author samoin
	 * @date 2011-07-06
	 * @version 0.1
	 * 
	 */
	class RegBtnsClickListeners implements OnClickListener {
		@Override
		public void onClick(View v) {
			if (v == goBack) {
				Intent intent = new Intent();
				intent.setClass(TopicCommentActivity.this,
						TopicDetailActivity.class);
				intent.putExtra("currentTopicId", currentTopicId);
				startActivity(intent);
			}
			if (v == publish) {
				// TODO 实际将该信息发布出去
				Intent intent = new Intent();
				intent.setClass(TopicCommentActivity.this,
						TopicDetailActivity.class);
				intent.putExtra("currentTopicId", currentTopicId);
				startActivity(intent);
			}
			if (v == topic_comment_comment) {
				if (topic_comment_comment
						.getText()
						.toString()
						.equals(getResources().getString(
								R.string.topic_comment_desc))) {
					topic_comment_comment.setText("");
				}
			}
		}
	}

	@Override
	public void setTitleViews() {
		LinearLayout titleLayout = getTITLE_LAYOUT();
		goBack = CustomTitleActivity.createTitleLeftButton(
				TopicCommentActivity.this, R.string.reg_title_btn_goback,
				Constants.TITLE_BTN_MARGIN1);
		goBack.setOnClickListener(rbc);
		titleLayout.addView((View) goBack.getParent());

		TextView tv = CustomTitleActivity.createTitleDesc(
				TopicCommentActivity.this, R.string.topic_comment_title, 0);
		titleLayout.addView((View) tv.getParent());

		publish = CustomTitleActivity.createTitleRightButton(
				TopicCommentActivity.this, R.string.topic_comment_publish,
				Constants.TITLE_BTN_MARGIN2);
		publish.setOnClickListener(rbc);
		LinearLayout ll = (LinearLayout) publish.getParent();
		ll.setGravity(Gravity.RIGHT);
		titleLayout.addView((View) publish.getParent());
	}

	@Override
	public void setLayoutId() {
		setContentView(R.layout.topic_comment);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		currentTopicId = getIntent().getLongExtra("currentTopicId", 0);
		type = getIntent().getIntExtra("type", 0);

		topic_comment_comment = (EditText) findViewById(R.id.topic_comment_comment);
		topic_comment_comment.setOnClickListener(rbc);

	}
}
